#ifndef NOEUD_H
#define NOEUD_H

#include "ct_itemdrawable/ct_scene.h"
#include "ct_pointcloudindex/ct_pointcloudindexvector.h"
#include "ct_itemdrawable/tools/iterator/ct_groupiterator.h"
#include "ct_result/ct_resultgroup.h"
#include "ct_result/model/inModel/ct_inresultmodelgroup.h"

// Alias for indexing in models
#define DEF_resultIn_inputResult "inputResult"
#define DEF_groupIn_inputScene "inputGroup"
#define DEF_itemIn_scene "inputScene"

#include <QDebug>

class Noeud
{


  public:

    Noeud();
    Noeud(Noeud* pere, unsigned int numFils, unsigned int *indPointDeb, unsigned int *indPointFin, CT_Scene* itemIn_scene);


    static Noeud *createRoot(unsigned int length, unsigned int *indPointDeb, unsigned int *indPointFin, unsigned int nbPtsMin, CT_Point pointLeftBot);


    void sortPointsFromPivot2(CT_ABSTRACT_MPCIR indexPointRe, unsigned int *sortFirstIndex,unsigned int *sortLastIndex,float pivot1, float pivot2, float pivot3, unsigned int* a, unsigned int* b,unsigned int* c,unsigned int* d,unsigned int* e,unsigned int* f,unsigned int* g);
    unsigned int sortPointsFromPivot(CT_ABSTRACT_MPCIR outSortedIndexCloudPtr,unsigned int sortFirstIndex,unsigned int sortLastIndex, float pivot,int sortAxis );

    void printDebug(CT_ABSTRACT_MPCIR indexPoint);

    bool isDivisible();
    bool isLeaf(Noeud * noeud);


    void subdivide(CT_ABSTRACT_MPCIR indexPointRe, Noeud* pere, CT_Scene* itemIn_scene);

    //void printDebug(CT_ABSTRACT_MPCIR indexPoint);

    void getCodeDeplacement(unsigned int nb, bool* deplX, bool* deplY, bool* deplZ );
    void codeBinFils(unsigned int nb, Noeud* pere, bool deplX, bool deplY , bool deplZ, bool* outCodeFilsX, bool* outCodeFilsY, bool* outCodeFilsZ );
    void getLeftPoint(Noeud* pere, bool deplX, bool deplY, bool deplZ, CT_Point* outLeftBot);

    float length;
    unsigned int depth;
    Noeud* fils[8];
    Noeud* pere;
    CT_Point pointLeftBot;

    bool* codeBinX;
    bool* codeBinY;
    bool* codeBinZ;
    unsigned int *indPointDeb;
    unsigned int *indPointFin;

    static unsigned int nbPtsMin;

};

#endif // NOEUD_H
